package com.yuan.order.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;

/**
 * 日期转换成秒数
 *
 * @Author yuan
 * @Date 2021/2/25 22:04
 */
public class DateToLongSerializer extends JsonSerializer<Date> {
    /**
     * Date除以1000，返回秒的数值
     *
     * @Author yuan
     * @Date 2021/2/25 22:05
     */
    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeNumber(date.getTime() / 1000);

    }
}
